package com.itqf.ipmsys.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itqf.ipmsys.dto.ParkingRecordDto;
import com.itqf.ipmsys.entity.ParkingRecord;
import com.itqf.ipmsys.mapper.ParkingRecordMapper;
import com.itqf.ipmsys.service.ParkingRecordService;
import com.itqf.ipmsys.vo.ParkingRecordVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 停车记录 服务实现类
 * </p>
 *
 * @author corn
 * @since 2021-09-22
 */
@Service
public class ParkingRecordServiceImpl extends ServiceImpl<ParkingRecordMapper, ParkingRecord> implements ParkingRecordService {

    @Resource
    private ParkingRecordMapper parkingRecordMapper;

    /**
     * /查询停车总次数
     *
     * @return 数量
     */
    @Override
    public Integer findParkingRecordCount() {
        Integer count = parkingRecordMapper.selectCount(null);
        return count;
    }

    /**
     * 查询总收入
     *
     * @return
     */
    @Override
    public Integer findPrices() {
        Integer prices = parkingRecordMapper.selectAllPrice();
        return prices;
    }

    /**
     * 查找所有停车记录,可以按条件检索
     * 查询信息:
     * 停车位、车牌号、停车时间(以结束时间检索)、收费员编号、收费员、路段编号、路段地址
     */
    @Override
    public Object findAllParkingRecordList(ParkingRecordDto parkingRecordDto) {
        //1. 分页属性:
        //      current:当前页
        //      size:每页显示条数，默认 10
        //      isSearchCount:是否返回总条数
        //      会自动拼接 limit sql语句,不用手写
        if (parkingRecordDto.getPageSize() == 0) {
            parkingRecordDto.setPageSize(10);
        }
        IPage<Map<String, Object>> page = new Page<>(parkingRecordDto.getPage(), parkingRecordDto.getPageSize());
        //2. 查找停车记录
        IPage<Map<String, ParkingRecordVo>> iPage = parkingRecordMapper.selectAllOrByKeys(page, parkingRecordDto);
        //3. 数据封装,返结果
        Map<String, Object> data = new HashMap<>(2);
        data.put("parkingrecords", iPage.getRecords());
        data.put("total", iPage.getTotal());
        return data;
    }

    /**
     * 查询最近正在进行的三个停车记录
     *
     * @return
     */
    @Override
    public Object findRecentThreeRecord() {
        List<Object> data = parkingRecordMapper.selectParkingThreeRecord();
        return data;
    }
}
